#!/usr/bin/env python3

import sys

f = open(sys.argv[1])
regs = []
found_regs = False
for l in f:
	if found_regs:
		try:
			regs.append(int(l, 16))
		except:
			break
	else:
		found_regs = "Register contents:" in l
assert(len(regs) == 32)

# Actual test:

assert(regs[1] == 0x20000)
assert(regs[2] == 0x40000)
assert(regs[3] == 0x20002000)
assert(regs[4] == 0x10001000)
assert(regs[5] == 0xe0002000)
assert(regs[6] == 0xf0001000)

assert(regs[7] == 0x1234 + 0x5678)
assert(regs[8] == 0x1234 + 0x7cd)
assert(regs[9] == (0x1234 - 0x5678) & 0xffffffff)
assert(regs[10] == 0x20008000)
assert((regs[11] & 0xfffff000)== 0x10000000)

assert(regs[12] == 0x1234 ^ 0x5678)
assert(regs[13] == 0xffffffff - 0x1234)
assert(regs[14] == 0x1234 | 0x5678)
assert(regs[15] == 0xffffffff)
assert(regs[16] == 0x1234 & 0x5678)
assert(regs[17] == 0x34)

assert(regs[18] == 0)
assert(regs[19] == 1)
assert(regs[20] == 1)
assert(regs[21] == 0)

print("Test PASSED.")